//
//  SYSeondaryView.m
//  SanYiTeaching
//
//  Created by 郑浩然 on 2019/4/17.
//  Copyright © 2019年 SanYi. All rights reserved.
//

#import "SYSeondaryView.h"
#import "SYCollectionTopView.h"
#import "SYBackTopView.h"
#import "SYCollectionTableView.h"
#import "SYCollectionView.h"

@interface SYSeondaryView () <SYBackTopViewDelegate,SYCollectionTopViewDelegate>

@property (strong, nonatomic) SYTopView *topView;

@property (strong, nonatomic) SYCollectionTopView *shearView;

@property (strong, nonatomic) SYBackTopView *backView;

@property (strong, nonatomic) UIView *zhongxinView;

@property (strong, nonatomic) UIViewController *vc;//模态vc

@property (strong, nonatomic) NSMutableArray *dataArr;

@property (strong, nonatomic) SYCollectionTableView *tableView;//表格形式

@property (strong, nonatomic) SYCollectionView *collectionView;


@end


@implementation SYSeondaryView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self initSubView];
    }
    return self;
}

- (void)viewSlidIntoSunbVC:(UIViewController *)vc{
    self.vc = vc;
    self.collectionView.hidden = NO;
    [self uikitHiddenView:NO];
    [self.tableView subUpViewArr:self.dataArr vc:self.vc WithIsFrom:self.isFrom];
    [self.collectionView subUpViewArr:self.dataArr vc:self.vc WithIsFrom:self.isFrom];
}


- (void)initSubView {
    
    [self addSubview:self.backView];
  
    self.dataArr = [[SYCollectionModel alloc] wekziwenjianshuju];
    
    [self.backView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.height.mas_equalTo(50);
    }];
    //顶部搜索
    [self addSubview:self.shearView];
    self.shearView.delegate = self;
    [self.shearView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.backView.mas_bottom).offset(0);
        make.left.right.equalTo(self);
        make.height.mas_equalTo(44);
    }];
    
    [self addCollection];
    [self addTableView];
    
    [self uikitHiddenView:YES];
}

- (void)addTableView {
    //表
    self.tableView = [[SYCollectionTableView alloc] init];
    [self addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.shearView.mas_bottom);
        make.left.bottom.right.equalTo(self);
    }];
    self.tableView.hidden = YES;
    
}
- (void)addCollection {
    __weak typeof(self) weakSelf = self;

    self.collectionView = [[SYCollectionView alloc] init];
    self.collectionView.stant = SYCollectionViewTypeWeiKeTiaoZhuan;
    self.collectionView.chooseZiYuanBlock = ^(SYCollectionModel *model) {
        if (weakSelf.chooseZiRetureBlock) {
            weakSelf.chooseZiRetureBlock(model);
        }
    };
    self.collectionView.hidden = YES;
    [self addSubview:self.collectionView];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.shearView.mas_bottom);
        make.left.bottom.right.equalTo(self);
    }];
    self.collectionView.block = ^(SYCollectionViewType type, SYCollectionModel *model) {
        [weakSelf seondaryHandleCallbackMethod:type collectionModel:model];
    };
    
}
//处理移动删除重命名，点击事件的数据
- (void)seondaryHandleCallbackMethod:(SYCollectionViewType)type collectionModel:(SYCollectionModel *)model {
    switch (type) {
        case SYCollectionViewTypeAll://刷新数据
            [self.tableView subUpViewArr:self.dataArr vc:self.vc WithIsFrom:self.isFrom];
            break;
        case SYCollectionViewTypeWeiKe://微课程
        {
            
        }
            break;
        case SYCollectionViewTypeWeiKeTiaoZhuan://微课程点击
        {
            
        }
            break;
        default:
            break;
    }
}


#pragma mark - SYCollectionTopViewDelegate
- (void)selectType:(SYCollectionTopType)type {
    switch (type) {
        case SYCollectionTopTypeAdd://添加文件夹---微课
        {
           
        }
            break;
        case SYCollectionTopTypeTab:
        {
            self.tableView.hidden = NO;
            self.collectionView.hidden = YES;
        }
            break;
        case SYCollectionTopTypeCollection:
        {
            self.tableView.hidden = YES;
            self.collectionView.hidden = NO;
        }
            break;
        case SYCollectionTopTypeUpload://上传
        {
            
        }
            break;
        case SYCollectionTopTypePaiZhao://拍照
        {
            
        }
            break;
        case SYCollectionTopTypeZhaoPian://照片
        {
            
        }
            break;
        case SYCollectionTopTypeLiuLan://浏览
        {
            
        }
            break;
        default:
            break;
    }
}



#pragma mark - setget
- (SYCollectionTopView *)shearView {
    if (!_shearView) {
        _shearView = [[SYCollectionTopView alloc] init];
        SYFunctoinModel *function = [[SYFunctoinModel alloc] init];
        function.titleName = @"微课";
        _shearView.function = function;
    }
    return _shearView;
}

- (SYBackTopView *)backView {
    if (!_backView) {
        _backView = [[SYBackTopView alloc] initWithTitleName:@"词汇评论" baseView:self];
        _backView.delegate = self;
    }
    return _backView;
}


#pragma mark-
//缩回去
- (void)backTopView {
    
}
- (void)uikitHiddenView:(BOOL)isHidden {
//    self.backView.hidden = isHidden;
    self.shearView.hidden = isHidden;
    
}

@end
